package com.easy.controller;

import com.easy.bean.Stylist;
import com.easy.service.StylistService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.print.Pageable;
import java.util.List;

@RestController
@CrossOrigin//允许跨域
@RequestMapping("/stylist")
public class StylistController {

    @Autowired
    StylistService stylistService;

    /**
     * 新增理发师
     */
    @PostMapping
    public Result add(@RequestBody Stylist stylist) {

            Object obj= stylistService.add(stylist);
            return Result.success(obj);

    }

    /**
     * 删除理发师（逻辑删除）
     */
    @DeleteMapping("{id}")
    public Result del(@PathVariable("id")Integer id) {

        Object obj = stylistService.del(id);
        return Result.success(obj);

    }

    /**
     * 修改理发师信息
     */
    @PutMapping
    public Result edit(@RequestBody Stylist stylist) {

        Object obj = stylistService.edit(stylist);
        return Result.success(obj);

    }

    /**
     * 查询所有理发师（带条件）
     */
    @GetMapping("all")
    public Result all(Stylist stylist) {

        Object obj = stylistService.all(stylist);
        return Result.success(obj);

    }

    /**
     * 根据ID查询单个理发师
     */
    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id) {

        Object obj = stylistService.one(id);
            return Result.success(obj);

    }

    /**
     * 分页查询理发师
     */
    @GetMapping("page")
    public Result page(Page page, Stylist stylist) {
        stylistService.page(page, stylist);
        //返回page对象
        return Result.success(page);
    }
}
